package com.example.dongha.bar.plotter;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

import com.example.dongha.bar.Axis;
import com.example.dongha.bar.AxisUtils;
import com.example.dongha.bar.listener.DateUtil;

/**
 * 类描述：
 * 创建人：lqh
 * 创建时间：2018/2/1
 * 修改人：
 * 修改时间：
 * 修改备注：
 *
 * @version v1.0
 */

public class ScaleTextPlotter implements Plotter {
    int height;
    private Axis axis;
    private Rect bound;
    private Paint paint;

    public ScaleTextPlotter(Axis axis) {
        this.axis = axis;
        this.bound = axis.getBound();
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setAlpha(150);
        paint.setStyle(Paint.Style.STROKE);
    }

    public void setColor(int color) {
        paint.setColor(color);
    }

    public void setTextSize(float textSize) {
        paint.setTextSize(textSize);
    }

    @Override
    public void draw(Canvas canvas, int height, float current) {
        this.height = height;


        for (int i = 0; i < axis.getShortLineCount(); i++) {

            drawTextValue(canvas, i);
        }

    }

    private void drawTextValue(Canvas canvas, int position) {
//        String text = position + "";
        String text = DateUtil.getDate(position) ;
        float x = axis.distance * position + axis.getBorderOffset() - paint.measureText(text) / 2;
        if (x < axis.currMinPixel - axis.distance || x > axis.currMaxPixel + axis.distance) {
            return;
        }
        canvas.drawText(text, x, height - AxisUtils.dpToPixel(220), paint);
    }

}
